﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class 入住信息 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            GridView1.Visible = false;
        }

    }
    protected void Bind()
    {
        users us = new users();
        GridView1.DataSource = us.Getone(us);
        GridView1.DataBind();
    }
    protected void btnSeart_Click(object sender, EventArgs e)
    {
        users us = new users();
        us.num = tbSeart.Text.Trim();
        GridView1.DataSource = us.Getone(us);
        GridView1.DataBind();
        GridView1.Visible = true;
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        Bind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        users tmp = new users();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex == GridView1.EditIndex)
            {
                DataRowView rowItem = (DataRowView)e.Row.DataItem;


            }
        }
        try
        {
            //获取”删除“链接
            LinkButton InkbtnDelete = (LinkButton)e.Row.Cells[15].Controls[0];
            //添加JavaScript代码实现客户端信息的提示
            InkbtnDelete.OnClientClick = "return confirm('请确认" + e.Row.Cells[1].Text + "的记录删除吗？');";

        }
        catch
        {

        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string number = GridView1.DataKeys[e.RowIndex].Value.ToString().Trim();
        users us = new users();
        us.number = number;
        us.Delete(us);
        Bind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        Bind();
        //GridView1.Visible = true;
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string number = GridView1.DataKeys[e.RowIndex].Value.ToString().Trim();
        string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim();
        string tel = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim();
        string rte = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim();
        string tte = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.Trim();
        string penson = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim();
        string num = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim();
        string type = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.Trim();
       


        users us = new users();
        us.number = number;
        us.name = name;
        us.tel = tel;
        us.rte = rte;
        us.tte = tte;
        us.penson = penson;
        us.num = num;
        us.type = type;
       

        us.Updahu2(us);
        //GridView1.EditIndex = -1;
        Bind();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        users us = new users();
        string sortExpression = e.SortExpression;
        if (GridView1.SortDirection == SortDirection.Ascending)
        {
            DataView dv = us.Gets(us).Tables[0].DefaultView;
            dv.Sort = sortExpression + "DESC";
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
        else
        {
            DataView dv = us.Gets(us).Tables[0].DefaultView;
            dv.Sort = sortExpression + "ASC";
            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
    }
}